package content
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class ListScroll extends MovieClip
	{
		private var _mcscroll:MovieClip;
		private var _allMc:Sprite
		private var _maskMc:Sprite;
		private var a:MovieClip;
		private var b:MovieClip;
		private var c:MovieClip;
		
		public function ListScroll(mc:Sprite,mask:Sprite)
		{
			_allMc=mc;
			_maskMc=mask;
			addPics();
			addEvents()

		}
		private var _scroll_move:Boolean=false;
		private var _lastc_y:Number=0;
		private var _lastmouse_y:Number=0;
		public function changeSize():void
		{
			b.y=_maskMc.height-b.height
			var bigH:Number=_allMc.height-_maskMc.height;
			var maxH:Number=_maskMc.height-(2*b.height);
			if(bigH>0){
				c.visible=true;
				c.height=maxH*(_maskMc.height/_allMc.height)
				
				if((c.y+c.height)>b.y){
					c.y=b.y-c.height;
				}
					
				
			}else{
				c.visible=false;
			}
		}
		public function speedNum(num:Number):void
		{
			var bigH:Number=_allMc.height-_maskMc.height;
			var maxH:Number=_maskMc.height-(2*b.height);
			if(bigH>0){
				var moveH:Number=(bigH/50*num);
				
				moveH=Math.abs(moveH)<6?num:moveH*2;
				
				
				var ty:Number=c.y+(bigH/50*num)
				ty=ty<a.height?a.height:ty;
				ty=ty>(b.y-c.height)?(b.y-c.height):ty;
				c.y=ty;
				_allMc.y=(c.y-a.height)/(_maskMc.height-a.height-b.height-c.height)*(-bigH)
			}
		}
		
		private function addEvents():void
		{
			c.addEventListener(MouseEvent.MOUSE_DOWN,cMouseDown)
			UiManege.stage.addEventListener(MouseEvent.MOUSE_UP,stageMouseUp)
			UiManege.stage.addEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove)
			
		}
		
		protected function stageMouseMove(event:MouseEvent):void
		{
			if(_scroll_move==true){
				var ty:Number=_lastc_y+(mouseY-_lastmouse_y);
				ty=ty<a.height?a.height:ty;
				ty=ty>(b.y-c.height)?(b.y-c.height):ty;
				c.y=ty;
				
				var bigH:Number=_allMc.height-_maskMc.height;
				_allMc.y=(c.y-a.height)/(_maskMc.height-a.height-b.height-c.height)*(-bigH)
			}
		}
		
		protected function stageMouseUp(event:MouseEvent):void
		{
			_scroll_move=false;
		}
		
		protected function cMouseDown(event:MouseEvent):void
		{
			_scroll_move=true;
			_lastc_y=c.y;
			_lastmouse_y=mouseY;
			
		}
		private function addPics():void
		{
			_mcscroll=UiManege.getClass("sample_scroll");
			addChild(_mcscroll);
			
			a=_mcscroll.a;
			b=_mcscroll.b;
			c=_mcscroll.c;
		}
	}
}